# Maintainer: Caleb Maclennan <caleb@alerque.com>
# Contributor: Jan de Groot <jgc@archlinux.org>
# Contributor: Bartłomiej Piotrowski <bpiotrowski@archlinux.org>
# Contributor: Tom Newsom <Jeepster@gmx.co.uk>
# Contributor: Jonas Hahnfeld <hahnjo@hahnjo.de>

pkgname=guile2.2
_pkgname=guile
pkgver=2.2.7
pkgrel=4
pkgdesc='Portable, embeddable Scheme implementation written in C'
url="https://www.gnu.org/software/$_pkgname/"
arch=(loong64 x86_64)
license=(GPL)
depends=(gc
         gmp
         libffi
         libltdl
         libunistring
         libxcrypt)
makedepends=(ncurses
             texinfo)
provides=(guile-readline.so
          libguile-2.2.so)
_archive="$_pkgname-$pkgver"
source=("https://ftp.gnu.org/pub/gnu/$_pkgname/$_archive.tar.gz"{,.sig})
validpgpkeys=('3CE464558A84FDC69DB40CFB090B11993D9AEBB5') # Ludovic Courtès <ludo@gnu.org>
sha256sums=('44b4c5fbbe257ccdebea18420212c9b3e90c3c86a54920d8554039fc6769a007'
            'SKIP')

build() {
	cd "$_archive"
	./configure \
		--prefix=/usr \
		--disable-static \
		--disable-error-on-warning \
		--program-suffix=2.2
	sed -e 's/ -shared / -Wl,-O1,--as-needed\0/g' -i libtool
	make
}

check() {
	cd "$_archive"
	make check
}

package() {
	make -C "$_archive" DESTDIR="$pkgdir" install
	sed -i "1s/$_pkgname/$pkgname/" -i "$pkgdir/usr/bin/guile-config2.2"
	rm "$pkgdir/usr/lib/"libguile-2.2.so.*-gdb.scm
	rm -rf "$pkgdir/usr/share/info" # conflicts with guile; ignores --program-suffix
	mv "$pkgdir/usr/share/aclocal/guile.m4" "$pkgdir/usr/share/aclocal/guile22.m4"
}
